home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mcomm557.zip / COMM.H < prev    next >
C/C++ Source or Header  |  1993-09-11  |  12KB  |  233 lines

  1.  
  2. /****************************************************************************
  3.  COMM.H -- header file for C programs using MCOMM5 Async Lib
  4.    Mike Dumdei,  6 Holly Lane,  Texarkana TX  75503    (c) 1989,1990
  5.  New COMM structure implemented in 5.42 <<< ALWAYS USE CURRENT COMM.H >>>
  6. ****************************************************************************/
  7.  
  8. #ifndef MCOMM
  9.   #define _C_ cdecl
  10.   #define _V_ volatile
  11.   #define _F_ far
  12.   #if (__TURBOC__ && __HUGE__)
  13.     #define _N_
  14.   #else
  15.     #define _N_ near
  16.   #endif
  17.   #define MCOMM
  18. #endif
  19.  
  20. /*  ---- Return codes ----  */
  21. #ifndef __ZTC__
  22.   #define       R_OK           0x0000
  23. #endif
  24. #define         R_NOMEM        0x0001
  25. #define         R_BAUDERR      0x0002
  26. #define         R_PARITYERR    0x0004
  27. #define         R_DTABITERR    0x0008
  28. #define         R_STPBITERR    0x0010
  29. #define         R_IRQUSED      0x0020
  30. #define         R_VCTRUSED     0x0040
  31. #define         R_NOPORT       0x0080
  32. #define         R_PORTUSED     0x0100
  33. #define         R_UARTERR      0x0200
  34.  
  35. #define         R_TXERR        0xffff
  36.  
  37. /* ---- Interrupt bit masks ---- */
  38. #define         IRQ2         0x04
  39. #define         IRQ3         0x08
  40. #define         IRQ4         0x10
  41. #define         IRQ5         0x20
  42. #define         IRQ6         0x40
  43. #define         IRQ7         0x80
  44.  
  45. /* ---- Vector numbers ---- */
  46. #define         VCTR2          10
  47. #define         VCTR3          11
  48. #define         VCTR4          12
  49. #define         VCTR5          13
  50. #define         VCTR6          14
  51. #define         VCTR7          15
  52.  
  53. /* ---- Standard Comm Ports ---- */
  54. #define         COM1        0x3f8, 0x10, 12
  55. #define         COM2        0x2f8, 0x08, 11
  56. #define         COM3        0x3e8, 0x10, 12
  57. #define         COM4        0x2e8, 0x08, 11
  58.  
  59. /* ---- Defines for Async_regs() ---- */
  60. #define         RXreg       0
  61. #define         TXreg       0
  62. #define         IERreg      1
  63. #define         IIDreg      2
  64. #define         FCRreg      2
  65. #define         LCRreg      3
  66. #define         MCRreg      4
  67. #define         LSRreg      5
  68. #define         MSRreg      6
  69. #define         LObaud      0
  70. #define         HIbaud      1
  71. #define         RDreg      (-1)
  72.  
  73. /* ---- Miscellaneous bits ---- */
  74. #define         B_DTR        0x0001
  75. #define         B_RTS        0x0002
  76.  
  77. /*  ---- Status bit masks ----  */
  78.                         /*    S T A T 2    */
  79. #define         B_XUSE       0x0001         /* using XON/XOFF protocol bit */
  80. #define         B_XRXD       0x0002                   /* XOFF received bit */
  81. #define         B_XSENT      0x0004                       /* XOFF sent bit */
  82. #define         B_TXEMPTY    0x0008             /* nothing to transmit bit */
  83. #define         B_CTS        0x0010                   /* clear to send bit */
  84. #define         B_DSR        0x0020                  /* data set ready bit */
  85. #define         B_FLOWHALT   0x0040             /* flow halt indicator bit */
  86. #define         B_MNTR_CD    0x0080                      /* monitor CD bit */
  87.  
  88.                         /*    S T A T 1    */
  89. #define         B_RXOVF      0x0100        /* rx buffer overflow indic bit */
  90. #define         B_OVERRUN    0x0200              /* char overrun error bit */
  91. #define         B_PARITY     0x0400                    /* parity error bit */
  92. #define         B_FRAMING    0x0800                   /* framing error bit */
  93. #define         B_BREAK      0x1000          /* line break signal detected */
  94. #define         B_THRE       0x2000      /* used by int handler (always 0) */
  95. #define         B_RXEMPTY    0x4000                 /* rx buffer empty bit */
  96. #define         B_CD         0x8000             /* carrier detect bit mask */
  97.  
  98.                         /*    S T A T 3    */
  99. #define         B_IGNERR     0x0001  /* discard chars with par, frm'g errs */
  100. #define         B_16550      0x0002                      /* 16550 detected */
  101. #define         B_FIFO       0x0004                 /* 16550 FIFOs enabled */
  102. #define         B_ORGFIFO    0x0008  /* FIFOs were on when port was opened */
  103. #define         B_XUSET      0x0020     /* using XON/XOFF on txmt side bit */
  104. #define         B_XUSER      0x0040     /* using XON/XOFF on recv side bit */
  105. #define         B_XONANY     0x0080          /* accept any char for an XON */
  106.  
  107.  
  108. /*  ----  P O R T   S T R U C T U R E   ---- */
  109.  
  110. #pragma pack(1)      /* be sure and use byte align to reference port struc */
  111.  
  112. typedef struct
  113. {
  114.     int ComBase;                     /* base port address of for comm port */
  115.     char IRQMask;                        /* mask for IRQ used by this port */
  116.     char Vector;                     /* interrupt vector used by this port */
  117.     char BPDSstr[10];               /* current baud,parity,data,stop parms */
  118.     int RxSize;                                    /* size of receive bufr */
  119.     int TxSize;                                   /* size of transmit bufr */
  120.     int RingSeg;              /* segment of rx/tx bufrs (leave 0 for NEAR) */
  121.     int RingOfst;                    /* offset of rx/tx bufrs, alias TxTop */
  122.     int RxTop;                     /* ptr to begin of rx bufr, alias TxBtm */
  123.     int RxBtm;                          /* ptr to end of rx bufr (end + 1) */
  124.     int _V_ TxIn;                          /* ptr to where next 'put' goes */
  125.     int _V_ TxOut;                    /* ptr to where next tx'd comes from */
  126.     int _V_ TxFree;                             /* remaining tx bufr space */
  127.     int _V_ RxIn;                       /* pointer to where next rx'd goes */
  128.     int _V_ RxOut;                   /* ptr to where next 'get' comes from */
  129.     int _V_ RxFree;                    /* remaining bytes in rx bufr space */
  130.     int BaudDvsr;                                     /* baud rate divisor */
  131.     int XoffTrip;          /* send XOFF when this many bytes left in rxbuf */
  132.     int XonTrip;            /* send XON when this many bytes left in rxbuf */
  133.     int OldVctrOfst;          /* OFST address of original interrupt vector */
  134.     int OldVctrSeg;            /* SEG address of original interrupt vector */
  135.     int OldDvsr;                    /* original value of Baud Divisor Regs */
  136.     char _V_ Stat2;                               /* secondary status byte */
  137.     char _V_ Stat1;                                 /* primary status byte */
  138.     char _V_ TxStat;          /* determines when tx_intrpts need turned on */
  139.     char MSRMask;               /* slcts bits in MSR montrd for flow cntrl */
  140.     char _V_ MSRVal;             /* present value of modem status register */
  141.     char _V_ Stat3;                  /* another flag, used for XONANY char */
  142.     char PDSinfo;                       /* parity, # dta bits, # stop bits */
  143.     char StripMask;                         /* mask for high bit stripping */
  144.     char XTxRptInit;              /* initialization value for XTxRpt below */
  145.     char _V_ XTxRpt;               /* countdown val befr repeat tx of XOFF */
  146.     char _V_ TxImmedChar;               /* char to be tx'd 1st opportunity */
  147.     char HdlrUsed;             /* assigned interrupt handler for this port */
  148.     char Old8259Msk;                       /* original 8259 interrupt mask */
  149.     char OldLCR;                        /* original Line Control Reg value */
  150.     char OldMCR;                         /* original Modem Cntrl Reg value */
  151.     char OldIER;                    /* original Interrupt Enable Reg value */
  152.     int TxByteCnt;                /* number bytes to send per tx interrupt */
  153.     char FCRVal;                        /* FIFO control register data byte */
  154.     char IERVal;                        /* interrupt enable register value */
  155.     char _V_ MCRVal;                       /* modem control register value */
  156. /*
  157.         Anything you want to add to this structure, such as a FILE *
  158.         associated with the port, status flags, buffer pointers, etc.,
  159.         can be added here at the bottom of the primary structure and
  160.         accessed through the same pointer used for the port.
  161. */
  162. } ASYNC;
  163.  
  164. #pragma pack()                      /* back to default structure alignment */
  165.  
  166. #ifdef __c